//螺旋矩阵 力扣59
class Solution {
public:
	vector<vector<int>> generateMatrix(int n) 
	{
		vector<vector<int>> a(n,vector<int>(n,0));
		int n2 = n*n;
		int k = n/2;
		int startx = 0;
		int starty = 0;
		int offset = 0;
		int count = 1;
		int x = 0;
		int y = 0;
		while(k--)
		{
			x = startx;
			y = starty;
			for(  ; x < n-1 - offset; x++)
				a[y][x] = count++;
			
			for(  ; y < n - 1 -offset; y++)
				a[y][x] = count++;
			
			for(  ; x > 0 + offset; x--)
				a[y][x] = count++;
			
			for(  ; y > 0 + offset; y--)
				a[y][x] = count++;
			
			startx++;
			starty++;
			offset++;
			
		}
		if(n%2 != 0)
			a[starty][startx] = count;
		return a;
		
	}
};
